package com.jsb.laundry.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@EnableScheduling
@Component
public class PushJobs {
    //推送1
    public static void push(String userId) throws Exception {
        JSONObject object = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        List list = new ArrayList();
        list.add("alluser");
        object.put("getuitag",list);
        object.put("content","您有一条新的消息");
        object.put("title","您有一条新的消息");
        jsonObject.put("text","您有一条新的消息");
        object.put("payload",jsonObject);
        System.out.println(object);
//        String post = HttpUtil.sendPost("https://fc-mp-45a514a0-ebd5-4460-8059-f4f9eea23d3b.next.bspapp.com/pushtest", null, JSONObject.toJSONString(object));
        String response = HttpPostUtil.doPost("https://fc-mp-45a514a0-ebd5-4460-8059-f4f9eea23d3b.next.bspapp.com/pushtest", "application/json", String.valueOf(object));
        System.out.println(response);
    }

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("b84538f1b9fa412882bc93103a96ff56");
        List byCid = findByCid(list);
        tag(byCid,"ceishi");
        List lists = new ArrayList();
        lists.add("ceishi");
        pushNew(lists,"马吊饭是傻逼123");

    }
    //根据 用户id查询 cid
    public static List findByCid(List data){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("alias",data);
        String response = HttpPostUtil.doPost("https://fc-mp-45a514a0-ebd5-4460-8059-f4f9eea23d3b.next.bspapp.com/getCidByAlias", "application/json", String.valueOf(jsonObject));
        System.out.println(response);
        JSONObject object = JSON.parseObject(response);
        JSONObject dataObject = object.getJSONObject("data");
        JSONArray cidArray = dataObject.getJSONArray("cid");
        System.out.println(cidArray);
        return cidArray;
    }
    //根据cid给用户打上标签
    public static List tag(List cid,String tag){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("cids",cid);
        jsonObject.put("custom_tag",tag);
        System.out.println(jsonObject);
        String response = HttpPostUtil.doPost("https://fc-mp-45a514a0-ebd5-4460-8059-f4f9eea23d3b.next.bspapp.com/moreuseronetag", "application/json", String.valueOf(jsonObject));
        System.out.println(response);
        return null;
    }
    //推送2
    public static void pushNew(List tag,String content){
        JSONObject object = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        List list = new ArrayList();
        JSONObject values = new JSONObject();
        values.put("key","custom_tag");
        values.put("values",tag);
        values.put("opt_type","and");
        list.add(values);
        object.put("getui_big_data_tag",list);
        object.put("content",content);
        object.put("title","您有一条新的消息");
        jsonObject.put("text","您有一条新的消息");
        object.put("payload",jsonObject);
        System.out.println(object);
        String response = HttpPostUtil.doPost("https://fc-mp-45a514a0-ebd5-4460-8059-f4f9eea23d3b.next.bspapp.com/pushtest", "application/json", String.valueOf(object));
        System.out.println(response);
    }
}
